package com.novoda.runbuddy.activity;

import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;

import com.novoda.runbuddy.R;
import com.novoda.runbuddy.provider.ActivityID;

public class TabsAdapter extends TabActivity {
	private Bundle	extras;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.tabs_adapter);

		TabHost tabs = getTabHost();
		this.extras = getIntent().getExtras();

		for (int i = 0; i < (extras.size() - 1) - ((extras.size() - 1) * 0.5); i++) {
			String currentNo = new String(Integer.toString(i));
			String name = (String) this.extras.get("name" + currentNo);
			String activity = (String) this.extras.get("tab" + currentNo);

			ComponentName activityByReference = new ComponentName(ActivityID.package_context, ActivityID.activities_package
					+ activity);

			TabHost.TabSpec tab = tabs.newTabSpec(activity);
			tab.setContent(new Intent().setComponent(activityByReference));
			tab.setIndicator(name);
			tabs.addTab(tab);
		}

		tabs.setCurrentTab(this.extras.getInt("default"));

	}

	public static class MyTabIndicator extends LinearLayout {
		public MyTabIndicator(Context context, String label) {
			super(context);

			View tab = LayoutInflater.from(context).inflate(R.layout.tab, this);

			TextView textView = (TextView) tab.findViewById(R.id.tab_label);
			textView.setText(label);
		}
	}
}